//
//  ACCache.h
//  ACCache_Example
//
//  Created by autohome on 2021/8/7.
//  Copyright © 2021 CaiXiang. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ACMemoryCache.h"
#import "ACDiskCache.h"
#import "ACCacheConfiguration.h"

NS_ASSUME_NONNULL_BEGIN

@interface ACCache : NSObject

@property (strong, nonatomic, readonly) ACCacheConfiguration *config;
@property (strong, nonatomic,readonly) ACMemoryCache *memoryCache;
@property (strong, nonatomic,readonly) ACDiskCache *diskCache;

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)cacheWithConfiguration:(ACCacheConfiguration *)config;

@end

@interface ACCache (ACExtension)

- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key;
- (void)setObject:(nullable id<NSCoding>)object forKey:(NSString *)key toDisk:(BOOL)yesOrNo;
- (void)setObject:(nullable id)object vaule:(nullable id)vaule forKey:(NSString *)key;
- (void)setObject:(nullable id)object vaule:(nullable id)vaule forKey:(NSString *)key toDisk:(BOOL)yesOrNo;

@end

@interface ACCache (Extension)

- (BOOL)containsObjectForKey:(NSString *)key;
- (nullable id<NSCoding>)objectForKey:(NSString *)key;
- (void)removeObjectForKey:(NSString *)key;
- (void)removeAllObjects;

@end

@interface ACCache (DBExtension)

- (BOOL)insertObject:(id<ACORMObjectProtocol>)object;
- (BOOL)insertObject:(id<ACORMObjectProtocol>)object
                into:(NSString *)tableName;
- (BOOL)insertObjects:(NSArray<id<ACORMObjectProtocol>> *)objects;
- (BOOL)insertObjects:(NSArray<id<ACORMObjectProtocol>> *)objects
                 into:(NSString *)tableName;
- (BOOL)insertObjectsInTransaction:(NSArray<id<ACORMObjectProtocol>> *)objects
                              into:(NSString*)tableName;
- (BOOL)insertOrReplaceObject:(id<ACORMObjectProtocol>)object
                         into:(NSString *)tableName;
- (BOOL)insertOrReplaceObjects:(NSArray<id<ACORMObjectProtocol>> *)objects
                          into:(NSString *)tableName;
- (BOOL)insertOrReplaceObjectsInTransaction:(NSArray<id<ACORMObjectProtocol>> *)objects
                              into:(NSString*)tableName;
- (BOOL)updateObjectClazz:(Class)clazz keyValues:(NSDictionary *)keyValues cond:(NSString *)predicateFormat,...;
- (BOOL)updateTableName:(NSString*)tableName objectClazz:(Class)clazz keyValues:(NSDictionary *)keyValues cond:(NSString *)predicateFormat,...;
- (NSArray*)getAllObjectsWithClass:(Class)clazz;
- (NSArray*)getAllObjectsWithClass:(Class)clazz withTableName:(NSString*)tableName;
- (NSArray *)getObjectsWithClass:(Class)clazz whereCond:(NSString *)predicateFormat, ...;
- (NSArray *)getObjectsWithClass:(Class)clazz withTableName:(NSString*)tableName whereCond:(NSString *)predicateFormat, ...;
- (NSArray *)getObjectsWithClass:(Class)clazz withTableName:(NSString*)tableName CustomCond:(NSString *)predicateFormat, ...;
- (NSArray *)getObjectsWithClass:(Class)clazz withTableName:(NSString*)tableName orderBy:(NSString*)orderName limit:(NSInteger)count cond:(NSString *)predicateFormat, ...;

- (NSArray *)getResultDictionaryWithTableName:(NSString*)tableName CustomCond:(NSString *)predicateFormat, ...;

- (BOOL)removeTableWithClass:(Class)clazz;
- (BOOL)removeTable:(NSString*)tableName;

@end


NS_ASSUME_NONNULL_END
